﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LightEngine
{
    namespace Utilities
    {
        namespace Types
        {


            public struct NamedType<NType>
            {
                public NType Value;
                public String Name;
            }

            public class NamedValue<Item>
                where Item : IComparable
            {

                private List<NamedType<Item>> NamedElements = new List<NamedType<Item>>();

                public Boolean AddNamingValue(Item Value, String Name)
                {
                    NamedType<Item> Element;
                    try
                    {
                        Element = NamedElements.First(new Func<NamedType<Item>, Boolean>((NamedType<Item> ExistingElement) => ExistingElement.Value.CompareTo(Value) == 0));
                        return false;
                    }

                    catch (InvalidOperationException Exception)
                    {
                        Exception.ToString();
                        // Элесент отсутсвует, можно добавлять..
                        Element.Value = Value;
                        Element.Name = Name;
                        NamedElements.Add(Element);
                        return true;
                    }
                }

                public String[] ReceiveDescriptionStringsArray()
                {
                    IEnumerable<String> ElementsDescription = (from NamedType<Item> Element in NamedElements
                                                               select Element.Name);
                    return ElementsDescription.ToArray<String>();
                }

                public String GetNameByValue(Item Value)
                {
                    NamedType<Item> Element;
                    try
                    {
                        Element = NamedElements.First(new Func<NamedType<Item>, Boolean>((NamedType<Item> ExistingElement) => ExistingElement.Value.CompareTo(Value) == 0));
                        return Element.Name;
                    }

                    catch (InvalidOperationException Exception)
                    {
                        Exception.ToString();
                        // Элесент отсутсвует, можно добавлять..
                        return String.Empty;
                    }
                }
            }
        }
    }
}
